package cn.lcsjsxy.yxc.objectoriented.学生类Json;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

public class JsonTest {

    @Test
    public void testWriteJson() throws JsonProcessingException {
        Dog dog=new Dog("佑诚~");
        Student student=new Student(100,"哇哦");

        //将student对象转换成一个字符串     Gson jackson Fastjson
        ObjectMapper objectMapper=new ObjectMapper();
        String studentStr = objectMapper.writeValueAsString(student);
        System.out.println(studentStr);
    }

    @Test
    public void testReadJson() throws JsonProcessingException {
        String studentStr="{\"name\":\"哇哦\",\"score\":100.0}";
        ObjectMapper objectMapper=new ObjectMapper();
        Student student2=objectMapper.readValue(studentStr, Student.class);
        System.out.println(student2);
    }

}
